package com.xhh.microfin.dispatch.service.process;

import com.xhh.microfin.dispatch.model.entity.ProcessNode;
import com.xhh.microfin.dispatch.model.entity.Task;
import com.xhh.microfin.dispatch.service.process.impl.ProcessContext;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
 * @Author: 003035
 * @Date: 2019/1/16
 */
public interface ITask {

    ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();

    /**
     * 节点推进
     *
     * @param task
     */
    void process(Task task);

    /**
     * 开始
     *
     * @param processNode
     * @param processInstanceId
     */
    Task begin(ProcessNode processNode, Integer processInstanceId);

    /**
     * 激活节点
     *
     * @param task
     */
    boolean active(Task task, ProcessContext context);

    /**
     * 是否已完成
     *
     * @param task
     * @return
     */
    boolean canBeDone(Task task, ProcessContext context);

    /**
     * 是否可以激活
     *
     * @param task
     * @return
     */
    boolean canBeActive(Task task, ProcessContext context);

    /**
     * @param task
     * @return
     */
    boolean canBeSelect(Task task, ProcessContext context);

    /**
     * 完成节点
     *
     * @param task
     * @return
     */
    boolean done(Task task, ProcessContext context);

    /**
     * 开始下一节点
     *
     * @param task
     */
    void next(Task task, ProcessContext context);

    /**
     * 获取context
     *
     * @return
     */
    EvaluationContext buildEvaluationContext(ProcessContext processContext);

    default ExpressionParser getExpressionParser() {
        return EXPRESSION_PARSER;
    }
}
